//**************************************************************//
//  Effect File exported by RenderMonkey 1.6
//
//  - Although many improvements were made to RenderMonkey FX  
//    file export, there are still situations that may cause   
//    compilation problems once the file is exported, such as  
//    occasional naming conflicts for methods, since FX format 
//    does not support any notions of name spaces. You need to 
//    try to create workspaces in such a way as to minimize    
//    potential naming conflicts on export.                    
//    
//  - Note that to minimize resulting name collisions in the FX 
//    file, RenderMonkey will mangle names for passes, shaders  
//    and function names as necessary to reduce name conflicts. 
//**************************************************************//

//--------------------------------------------------------------//
// Ocean
//--------------------------------------------------------------//
//--------------------------------------------------------------//
// Sky
//--------------------------------------------------------------//
string Reflection_Refraction_and_Water_Effects_Ocean_Sky_Sky_Sphere : ModelData = "E:\\Program Files\\AMD\\RenderMonkey 1.71\\Examples\\Media\\Models\\Sphere.3ds";

float4x4 view_proj_matrix : ViewProjection;
float4 view_position : ViewPosition;
struct VS_OUTPUT {
   float4 Pos: POSITION;
   float3 pos: TEXCOORD0;
};

VS_OUTPUT Reflection_Refraction_and_Water_Effects_Ocean_Sky_Vertex_Shader_main(float4 Pos: POSITION){
   VS_OUTPUT Out;

   // Lock environment to view position
   Out.Pos = mul(view_proj_matrix, float4(Pos.xyz + view_position, 1));
   Out.pos = Pos.yzx;

   return Out;
}






texture skyBox_Tex
<
   string ResourceName = "E:\\Program Files\\AMD\\RenderMonkey 1.71\\Examples\\Media\\Textures\\Snow.dds";
>;
sampler skyBox = sampler_state
{
   Texture = (skyBox_Tex);
   ADDRESSU = CLAMP;
   ADDRESSV = CLAMP;
   MAGFILTER = LINEAR;
   MINFILTER = LINEAR;
   MIPFILTER = LINEAR;
};
float4 Reflection_Refraction_and_Water_Effects_Ocean_Sky_Pixel_Shader_main(float3 pos: TEXCOORD0) : COLOR {
   return texCUBE(skyBox, pos);
}


//--------------------------------------------------------------//
// Water
//--------------------------------------------------------------//
string Reflection_Refraction_and_Water_Effects_Ocean_Water_Quad : ModelData = "E:\\Program Files\\AMD\\RenderMonkey 1.71\\Examples\\Media\\Models\\OceanSurface.3ds";

float4x4 Reflection_Refraction_and_Water_Effects_Ocean_Water_Vertex_Shader_view_proj_matrix : ViewProjection;
float4 scale
<
   string UIName = "scale";
   string UIWidget = "Direction";
   bool UIVisible =  true;
   float4 UIMin = float4( 0.00, 0.00, 0.00, 0.00 );
   float4 UIMax = float4( 0.01, 0.01, 0.01, 0.01 );
   bool Normalize =  false;
> = float4( 0.01, 0.01, 0.01, 1.00 );

float4 Reflection_Refraction_and_Water_Effects_Ocean_Water_Vertex_Shader_view_position : ViewPosition;

//alex@below
float Reflection_Refraction_and_Water_Effects_Ocean_Water_Pixel_Shader_time_1_X : Time0_X;
//alex@above

struct Reflection_Refraction_and_Water_Effects_Ocean_Water_Vertex_Shader_VS_OUTPUT {
   float4 Pos:    POSITION;
   float3 pos:    TEXCOORD0;
   float3 normal: TEXCOORD1;
   float3 vVec:   TEXCOORD2;
};

Reflection_Refraction_and_Water_Effects_Ocean_Water_Vertex_Shader_VS_OUTPUT Reflection_Refraction_and_Water_Effects_Ocean_Water_Vertex_Shader_main(float4 Pos: POSITION, float3 normal: NORMAL){
   Reflection_Refraction_and_Water_Effects_Ocean_Water_Vertex_Shader_VS_OUTPUT Out;

   // Get some size on the water
   Pos.xy *= 1000;
   Pos.z = -30;
   
   //alex@below
   Out.Pos = mul(Reflection_Refraction_and_Water_Effects_Ocean_Water_Vertex_Shader_view_proj_matrix, Pos);
   //alex@above
   
   //backup
   //Out.Pos = mul(Reflection_Refraction_and_Water_Effects_Ocean_Water_Vertex_Shader_view_proj_matrix, Pos);
   Out.pos = Pos.xyz * scale;
   Out.vVec = Pos - Reflection_Refraction_and_Water_Effects_Ocean_Water_Vertex_Shader_view_position;
   Out.normal = normal;

   return Out;
}










float waveSpeed
<
   string UIName = "waveSpeed";
   string UIWidget = "Numeric";
   bool UIVisible =  true;
   float UIMin = 0.00;
   float UIMax = 1.00;
> = float( 0.80 );
float noiseSpeed
<
   string UIName = "noiseSpeed";
   string UIWidget = "Numeric";
   bool UIVisible =  true;
   float UIMin = 0.00;
   float UIMax = 1.00;
> = float( 0.20 );
float fadeBias
<
   string UIName = "fadeBias";
   string UIWidget = "Numeric";
   bool UIVisible =  true;
   float UIMin = 0.00;
   float UIMax = 1.00;
> = float( 0.30 );
float fadeExp
<
   string UIName = "fadeExp";
   string UIWidget = "Numeric";
   bool UIVisible =  true;
   float UIMin = 0.00;
   float UIMax = 8.00;
> = float( 6.08 );
float Reflection_Refraction_and_Water_Effects_Ocean_Water_Pixel_Shader_time_0_X : Time0_X;
float4 waterColor
<
   string UIName = "waterColor";
   string UIWidget = "Color";
   bool UIVisible =  true;
> = float4( 0.20, 0.35, 0.68, 1.00 );
texture Noise_Tex
<
   string ResourceName = "E:\\Program Files\\AMD\\RenderMonkey 1.71\\Examples\\Media\\Textures\\NoiseVolume.dds";
>;
sampler Noise = sampler_state
{
   Texture = (Noise_Tex);
   ADDRESSU = WRAP;
   ADDRESSV = WRAP;
   ADDRESSW = WRAP;
   MAGFILTER = LINEAR;
   MINFILTER = LINEAR;
   MIPFILTER = LINEAR;
};
sampler Reflection_Refraction_and_Water_Effects_Ocean_Water_Pixel_Shader_skyBox = sampler_state
{
   Texture = (skyBox_Tex);
   ADDRESSU = CLAMP;
   ADDRESSV = CLAMP;
   MAGFILTER = LINEAR;
   MINFILTER = LINEAR;
   MIPFILTER = LINEAR;
};
float4 Reflection_Refraction_and_Water_Effects_Ocean_Water_Pixel_Shader_main(float3 pos: TEXCOORD0, float3 normal: TEXCOORD1, float3 vVec: TEXCOORD2) : COLOR {
   pos.x += waveSpeed  * Reflection_Refraction_and_Water_Effects_Ocean_Water_Pixel_Shader_time_0_X;
   pos.z += noiseSpeed * Reflection_Refraction_and_Water_Effects_Ocean_Water_Pixel_Shader_time_0_X;

   float4 noisy = tex3D(Noise, pos);

   // Signed noise 
   float3 bump = 2 * noisy - 1;
   bump.xy *= 0.15;
   // Make sure the normal always points upwards
   bump.z = 0.8 * abs(bump.z) + 0.2;
   // Offset the surface normal with the bump
   bump = normalize(normal + bump);

   // Find the reflection vector
   float3 reflVec = reflect(vVec, bump);
   float4 refl = texCUBE(Reflection_Refraction_and_Water_Effects_Ocean_Water_Pixel_Shader_skyBox, reflVec.yzx);

   float lrp = 1 - dot(-normalize(vVec), bump);

   // Interpolate between the water color and reflection
   return lerp(waterColor, refl, saturate(fadeBias + pow(lrp, fadeExp)));
}



//--------------------------------------------------------------//
// Technique Section for Effect Workspace.Reflection Refraction and Water Effects.Ocean
//--------------------------------------------------------------//
technique Ocean
{
   pass Sky
   {
      ZENABLE = FALSE;
      CULLMODE = CW;

      VertexShader = compile vs_1_1 Reflection_Refraction_and_Water_Effects_Ocean_Sky_Vertex_Shader_main();
      PixelShader = compile ps_2_0 Reflection_Refraction_and_Water_Effects_Ocean_Sky_Pixel_Shader_main();
   }

   pass Water
   {
      ZENABLE = TRUE;
      CULLMODE = NONE;

      VertexShader = compile vs_2_0 Reflection_Refraction_and_Water_Effects_Ocean_Water_Vertex_Shader_main();
      PixelShader = compile ps_2_0 Reflection_Refraction_and_Water_Effects_Ocean_Water_Pixel_Shader_main();
   }

}

